<template>
  <div class="app-container">
    <el-form :inline="true" ref="form" :model="queryParams" class="demo-form-inline">

      <el-form-item label="标题" prop="title">
        <el-input v-model="queryParams.title" placeholder="标题" />
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="top-fun">
      <el-button type="success" @click="handleAdd">新增</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="标题	" align="center" prop="title" />

      <el-table-column label="创建时间	" align="center" prop="createTime" />

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="handleShowInfo(scope.row)">详情</el-button>
          <el-button type="text" style="color: red;" @click="handleDel(scope.row)">删除</el-button>

        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        :current-page.sync="queryParams.pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="fetchData"
        @current-change="fetchData"
      />
    </div>
    <ShowInfo ref="showInfo" />
  </div>
</template>

<script>
import { noticeList ,noticeDel} from '@/api/table'
import ShowInfo from './add.vue'
export default {
  components: {
    ShowInfo

  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      typeOptions: [
        { label: '虚拟货币', value: 'usdt' },
        { label: '人民币', value: 'rmb' }
      ],
      statusOptions: [
        { label: '申请中', value: 'applying' },
        { label: '审核通过', value: 'approved' },
        { label: '审核驳回', value: 'reject' }

      ],
      queryParams: {

        title: '',
        pageNum: 1,
        pageSize: 10,
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      noticeList(this.queryParams).then(response => {
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },
    handleShowInfo(e) {
      this.$refs.showInfo.edit(e)
    },
    setStateTxt(index) {
      let str = ''
      switch (index) {
        case 'applying':
          str = '申请中'
          break
        case 'approved':
          str = '审核通过'
          break
        case 'reject' :
          str = '审核驳回'
          break
      }
      return str
    },
    onSubmit() {
      this.queryParams.page = 1
      this.fetchData()
    },
    reset() {
      this.$refs.form.resetFields()
      this.fetchData()
    },
    handleAdd() {
      this.$refs.showInfo.show()
    },
    handleEdit(e) {
      this.$refs.add.edit(e)
    },
    handleDel(e) {
      this.$confirm('此操作将删除公告, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        noticeDel({id:e.id}).then(res => {
          this.fetchData()
          this.$message({
            type: 'success',
            message: '成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    }
  }
}
</script>
